<?php

/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 2017/8/20
 * Time: 下午8:52
 */
class AuctionService extends Service
{

    public static function indexHeader(){
        return array(
            'PlatID'            => array('text' => '平台'),
            'GameSvrId'         => array('text' => '服务器'),
            'dtEventTime'       => array('text' => '事件时间'),
            'RecordItemId'      => array('text' => '交易ID'),
            'SellRole'          => array('text' => '卖出玩家'),
            'BuyRole'           => array('text' => '买进玩家'),
            'ItemType'          => array('text' => '物品类型'),
            'Item'              => array('text' => '物品'),
            'IsRare'            => array('text' => '是否珍品'),
            'TradeRecPrice'     => array('text' => '市场价格'),
            'TradeItemPrice'    => array('text' => '交易价格'),
            'TradeItemNum'      => array('text' => '交易数量'),
            'TradeTurnover'     => array('text' => '交易总额'),
            'NewItemID'         => array('text' => '玩家买进后新物品ID'),
            'Action'            => array('text' => '操作'),

        );
    }

    public static function indexData($params){
        $data = ModAuction::indexData($params);

        $serverId = PubServer::getPkByDevId($params['server']);
        $game     = $params['g'];

        foreach($data as &$v){
            $strVal = base64_encode(json_encode($v));

            $v['SellRole']  = "{$v['SellRoleName']}<br/><a href='/oss/?r=role/index&m=36&g={$game}&server={$serverId}&search={$v['SellRoleID']}' target='_blank'>{$v['SellRoleID']}</a>";
            $v['BuyRole']   = "{$v['BuyRoleName']}<br/><a href='/oss/?r=role/index&m=36&g={$game}&server={$serverId}&search={$v['BuyRoleID']}' target='_blank'>{$v['BuyRoleID']}</a>";

            $v['Item']      = "{$v['ItemName']}<br/><span style='color: grey;'>{$v['ItemID']}</span>";

//            if($v['TradeItemPrice'] > $v['TradeRecPrice']){
//                $v['TradeItemPrice'] = "<span style='color: red;'>{$v['TradeItemPrice']} ↑</span>";
//            }else if($v['TradeItemPrice'] < $v['TradeRecPrice']){
//                $v['TradeItemPrice'] = "<span style='color: green;'>{$v['TradeItemPrice']} ↓</span>";
//            }

            $v['Action'] = "<div>";
            $v['Action'] .= "<a class='fancybox' href='/oss/?r=auction/action&g={$game}&server={$serverId}&type=cancel&data={$strVal}'>交易取消</a>";
            $v['Action'] .= " | <a class='fancybox' href='/oss/?r=auction/action&g={$game}&server={$serverId}&type=frozen&data={$strVal}'>材料冻结</a>";
            $v['Action'] .= " | <a class='fancybox' href='/oss/?r=auction/action&g={$game}&server={$serverId}&type=bond&data={$strVal}'>保证金扣除</a>";
            $v['Action'] .= "<br/>";
            $v['Action'] .= "<a class='fancybox' href='/oss/?r=auction/action&g={$game}&server={$serverId}&type=close&data={$strVal}'>屏蔽寄售</a>";
            $v['Action'] .= " | <a href='/oss/?r=operation/ban&g={$game}&server={$serverId}&uid={$v['SellRoleID']}' target='_blank'>卖家封号</a>";
            $v['Action'] .= " | <a href='/oss/?r=operation/ban&g={$game}&server={$serverId}&uid={$v['BuyRoleID']}' target='_blank'>买家封号</a>";
            $v['Action'] .= "</div>";
        }
        unset($v);

        return $data;
    }

    public static function actionCancel($server, $params){
        if(PubFunc::checkEmpty($params, array('roleID', 'recordItemID'))){
            return array('state' => false, 'msg' => '参数不全');
        }

        $api = new ApiService($server);
        return $api->auctionCancel($params);
    }

    public static function actionFrozen($server, $params){
        if(PubFunc::checkEmpty($params, array('frozenTime'))){
            return array('state' => false, 'msg' => '参数不全');
        }

        $api = new ApiService($server);
        return $api->auctionFrozen($params);
    }

    public static function actionClose($server, $params){
        if(PubFunc::checkEmpty($params, array('endTime'))){
            return array('state' => false, 'msg' => '参数不全');
        }

        $api = new ApiService($server);
        return $api->auctionClose($params);
    }

    public static function actionBond($server, $params){
        if(PubFunc::checkEmpty($params, array('days'))){
            return array('state' => false, 'msg' => '参数不全');
        }

        $api = new ApiService($server);
        return $api->auctionBond($params);
    }
}